define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	var check = require("$UI/communityOto/common/check");

	var Model = function(){
	    this.timer = 0;
		this.callParent();
	};
	
	Model.prototype.areaDataCustomRefresh = function(event){
	    var url = "http://www.xjzlhy.com:81/ex_community/a/api/community/getAllNeighborhood?callback=?";
		$.getJSON(
				url,
				function(data){
					event.source.loadData(data.data);
				}
		
		);

	};
	
	
	
	
	
//	
//	Model.prototype.passwordBlur = function(event){
//		if(!check.testPassword($(event.currentTarget).val())){
//			justep.Util.hint("请输入以字母开头的6-18个字母、数字或下划线",{type:"danger"});
//		}
//	};
//	
//	
//
//	Model.prototype.loginNameBlur = function(event){
//	  if(!check.testUserName($(event.currentTarget).val())){
//		  justep.Util.hint("请输入以字母开头的5-15个字母、数字或下划线",{type:"danger"});
//	  }
//
//	};
//	
//	
//	Model.prototype.nameBlur = function(event){
//		if(!check.testName($(event.currentTarget).val())){
//		
//		     justep.Util.hint("请输入2个以上的汉字", {type:"danger"});
//		}
//	};
//	
//	
//	
//	Model.prototype.passwordBlur = function(event){
//		if(!check.testPassword($(event.currentTarget).val())){
//			justep.Util.hint("请输入以字母开头的6-18个字母、数字或下划线",{type:"danger"});
//		}
//	};
	
	

	Model.prototype.registAndbindClick = function(event){
	    var me = this;
		var  newUserData = this.comp("newUserData");
		var  formData = new FormData();
		
		if(newUserData.val('type')&&newUserData.val("office.id")&&newUserData.val("name")&&newUserData.val("password")&&newUserData.val("loginName")){	
			
			formData.append("office.id",newUserData.val("office.id"));
		    formData.append("name",newUserData.val("name"));
		    formData.append("password",newUserData.val("password"));
		    formData.append("loginName",newUserData.val("loginName"));
		    if(me.getParentModel().user.accountType == 'WX'){
		    	formData.append("openId",me.getParentModel().user.openId);
		    }else if(me.getParentModel().user.accountType == 'QQ' ){
		    	formData.append("qqId",me.getParentModel().user.openId);
		    }
		    
		    
			var userType = newUserData.val('type');
			newUserUrl = userType==1?"http://www.xjzlhy.com:81/ex_community/a/api/community/register":"http://www.xjzlhy.com:81/ex_community/a/api/community/businessReg";
			
				$.ajax({
				  url: newUserUrl,
				  type: "POST",
				  data: formData,
				  processData: false,  // 告诉jQuery不要去处理发送的数据
				  contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
				  success:function(data){
				        if(data.errNo != -1){
	                	      
							   localStorage.setItem("userInfo",JSON.stringify(data));
							   if(data.data[0].userType == '4'){
								   $('.MerchantMall').show();
								   $('.bisnessInfo').show();
							   }	
						       $(".rollText").text(data.data[1].name + "欢迎您，祝心想事成，万事如意！");  
						      
						       if(me.getParentModel().comp('body').getActiveIndex() == 3){
						    	   me.getParentModel().comp('mineContainer').setSrc('$UI/communityOto/mine/mineFragment.w');
						    	   me.getParentModel().comp('mineContainer').refresh();
						       }else{
						    	   me.getParentModel().comp("contentDialog").open({src:me.getParentModel().toPath});
						       }
						       justep.Util.hint("绑定成功",{delay:1000,position:"middle"});
						      // location.reload(true);
						      
						   }else{
							   justep.Util.hint("该用户已存在",{delay:1000,position:"middle"});
						   }
		  				
			      }
				});
		}else{
			justep.Util.hint("请补充完整必填信息", {type:"danger"});
		}

	};
	
	
	
	Model.prototype.input1Focus = function(event){
		var me = this;
		this.timer = setInterval(function() {
		    me.comp("searchAreaData").clear();
			var searchVal = me.comp("input1").val();
			if (searchVal) {
                
				var result = me.comp("areaData").find([ 'name' ], [ searchVal ], false, true, true);
                if (result.length > 0) {

					for (var i = 0; i < result.length; i++) {
						
						me.comp("searchAreaData").newData({
							defaultValues : [ {
								'id' : result[i].val('id'),
								'name' : result[i].val('name')
							} ]
						});

					}
					me.comp("list1").refresh();
					// this.comp("searchAreaData").first();
					// this.comp("searchAreaData").refreshData(true);
				}
				
			}
		}, 1000);
//	    
	    	
	    	
	   
	   

	};
	

	
	Model.prototype.input1Change = function(event){


        if(this.timer ){
        	clearInterval(this.timer);
        }

	};
	
	
	
	
	
	
	
	//选择社区事件	
	Model.prototype.list1Click = function(event){
		var currentRow = this.comp("searchAreaData").getCurrentRow();
		$('#'+this.getIDByXID("input1")).val(currentRow.val('name'));
		this.comp("newUserData").getFirstRow().val('office.id',currentRow.val('id'));
		this.comp("searchAreaData").clear();
		clearInterval(this.timer);

	};
		
	Model.prototype.input1Blur = function(event){
		 if(this.timer ){
        	clearInterval(this.timer);
        }
	};
	
	
	
	
	////发短信
	
	Model.prototype.sendSmsCode = function(event){
	
		var phone = this.comp("phone").val();
		if(phone){
			$.getJSON('http://www.xjzlhy.com:81/ex_community/a/api/community/sendMessage?callback=?&mobile='+phone,
			function(data){
				if(data.errMessage == 'ok'){
					
					justep.Util.hint('验证码已发送', {type:'success'});
				}
			
			});
			var seconds = 60;
			event.source.set({'label':seconds,'disabled':true});
			var timer = setInterval(function(){
				if(--seconds > 0){
					event.source.set({label:seconds});
				}else{
					event.source.set({'label':'发送','disabled':false});
					clearInterval(timer);
				}
				
			}, 1000);
		}
		



	};
	

	
	Model.prototype.nextStepClick  = function(event){
	
		var phone = this.comp("phone").val();
		var checkCode = this.comp("checkCode").val();
		var me = this;
		if(phone&&checkCode){
			$.getJSON('http://www.xjzlhy.com:81/ex_community/a/api/community/sendMessage?callback=?&mobile='+phone+'&code='+checkCode,
				function(data){
					if(data.errMessage = 'succeed'){
					    me.comp("newUserData").getFirstRow().val('loginName',phone);
						$('.checkCodePanel').hide();
						justep.Util.hint('验证码验证成功', {type:'success'});
						$('.registerPanel').show();
					}
				
				}
			);
			
		}

	};
	
	
	

	return Model;
});